
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/12/2013 14:07:17
-- Generated from EDMX file: H:\proj\NthParameterSeries\Coda.Nth.DbConnect\NthDbConnect.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Brett];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PortfolioPrice]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PriceSet] DROP CONSTRAINT [FK_PortfolioPrice];
GO
IF OBJECT_ID(N'[dbo].[FK__test__CountryId__1BFD2C07]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[test] DROP CONSTRAINT [FK__test__CountryId__1BFD2C07];
GO
IF OBJECT_ID(N'[dbo].[FK__test__CityID__276EDEB3]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[test] DROP CONSTRAINT [FK__test__CityID__276EDEB3];
GO
IF OBJECT_ID(N'[dbo].[FK_CountryPortfolio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PortfolioSet] DROP CONSTRAINT [FK_CountryPortfolio];
GO
IF OBJECT_ID(N'[dbo].[FK_CityPortfolio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PortfolioSet] DROP CONSTRAINT [FK_CityPortfolio];
GO
IF OBJECT_ID(N'[dbo].[FK_ManagerFee_inherits_Fee]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeeSet_ManagerFee] DROP CONSTRAINT [FK_ManagerFee_inherits_Fee];
GO
IF OBJECT_ID(N'[dbo].[FK_Rebate_inherits_Fee]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FeeSet_Rebate] DROP CONSTRAINT [FK_Rebate_inherits_Fee];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[PriceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PriceSet];
GO
IF OBJECT_ID(N'[dbo].[PortfolioSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PortfolioSet];
GO
IF OBJECT_ID(N'[dbo].[CountrySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CountrySet];
GO
IF OBJECT_ID(N'[dbo].[CitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CitySet];
GO
IF OBJECT_ID(N'[dbo].[FeeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeeSet];
GO
IF OBJECT_ID(N'[dbo].[test]', 'U') IS NOT NULL
    DROP TABLE [dbo].[test];
GO
IF OBJECT_ID(N'[dbo].[FeeSet_ManagerFee]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeeSet_ManagerFee];
GO
IF OBJECT_ID(N'[dbo].[FeeSet_Rebate]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeeSet_Rebate];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'PriceSet'
CREATE TABLE [dbo].[PriceSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [AsOfDate] datetime  NOT NULL,
    [Nav] decimal(18,0)  NOT NULL,
    [Ror] decimal(18,0)  NOT NULL,
    [EntryDate] datetime  NOT NULL,
    [Portfolio_Id] int  NOT NULL
);
GO

-- Creating table 'PortfolioSet'
CREATE TABLE [dbo].[PortfolioSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [InceptionDate] datetime  NOT NULL,
    [Address_City] nvarchar(max)  NOT NULL,
    [Address_Country] nvarchar(max)  NOT NULL,
    [CountryId] int  NULL,
    [CityId] int  NULL
);
GO

-- Creating table 'CountrySet'
CREATE TABLE [dbo].[CountrySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CitySet'
CREATE TABLE [dbo].[CitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'FeeSet'
CREATE TABLE [dbo].[FeeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'test'
CREATE TABLE [dbo].[test] (
    [id] int IDENTITY(1,1) NOT NULL,
    [name] varchar(100)  NULL,
    [CountryId] int  NULL,
    [CityID] int  NULL
);
GO

-- Creating table 'FeeSet_ManagerFee'
CREATE TABLE [dbo].[FeeSet_ManagerFee] (
    [Manger] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'FeeSet_Rebate'
CREATE TABLE [dbo].[FeeSet_Rebate] (
    [Characteristi] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'PriceSet'
ALTER TABLE [dbo].[PriceSet]
ADD CONSTRAINT [PK_PriceSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PortfolioSet'
ALTER TABLE [dbo].[PortfolioSet]
ADD CONSTRAINT [PK_PortfolioSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CountrySet'
ALTER TABLE [dbo].[CountrySet]
ADD CONSTRAINT [PK_CountrySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CitySet'
ALTER TABLE [dbo].[CitySet]
ADD CONSTRAINT [PK_CitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FeeSet'
ALTER TABLE [dbo].[FeeSet]
ADD CONSTRAINT [PK_FeeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [id] in table 'test'
ALTER TABLE [dbo].[test]
ADD CONSTRAINT [PK_test]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [Id] in table 'FeeSet_ManagerFee'
ALTER TABLE [dbo].[FeeSet_ManagerFee]
ADD CONSTRAINT [PK_FeeSet_ManagerFee]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FeeSet_Rebate'
ALTER TABLE [dbo].[FeeSet_Rebate]
ADD CONSTRAINT [PK_FeeSet_Rebate]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Portfolio_Id] in table 'PriceSet'
ALTER TABLE [dbo].[PriceSet]
ADD CONSTRAINT [FK_PortfolioPrice]
    FOREIGN KEY ([Portfolio_Id])
    REFERENCES [dbo].[PortfolioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PortfolioPrice'
CREATE INDEX [IX_FK_PortfolioPrice]
ON [dbo].[PriceSet]
    ([Portfolio_Id]);
GO

-- Creating foreign key on [CountryId] in table 'test'
ALTER TABLE [dbo].[test]
ADD CONSTRAINT [FK__test__CountryId__1BFD2C07]
    FOREIGN KEY ([CountryId])
    REFERENCES [dbo].[CountrySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__test__CountryId__1BFD2C07'
CREATE INDEX [IX_FK__test__CountryId__1BFD2C07]
ON [dbo].[test]
    ([CountryId]);
GO

-- Creating foreign key on [CityID] in table 'test'
ALTER TABLE [dbo].[test]
ADD CONSTRAINT [FK__test__CityID__276EDEB3]
    FOREIGN KEY ([CityID])
    REFERENCES [dbo].[CitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__test__CityID__276EDEB3'
CREATE INDEX [IX_FK__test__CityID__276EDEB3]
ON [dbo].[test]
    ([CityID]);
GO

-- Creating foreign key on [CountryId] in table 'PortfolioSet'
ALTER TABLE [dbo].[PortfolioSet]
ADD CONSTRAINT [FK_CountryPortfolio]
    FOREIGN KEY ([CountryId])
    REFERENCES [dbo].[CountrySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CountryPortfolio'
CREATE INDEX [IX_FK_CountryPortfolio]
ON [dbo].[PortfolioSet]
    ([CountryId]);
GO

-- Creating foreign key on [CityId] in table 'PortfolioSet'
ALTER TABLE [dbo].[PortfolioSet]
ADD CONSTRAINT [FK_CityPortfolio]
    FOREIGN KEY ([CityId])
    REFERENCES [dbo].[CitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CityPortfolio'
CREATE INDEX [IX_FK_CityPortfolio]
ON [dbo].[PortfolioSet]
    ([CityId]);
GO

-- Creating foreign key on [Id] in table 'FeeSet_ManagerFee'
ALTER TABLE [dbo].[FeeSet_ManagerFee]
ADD CONSTRAINT [FK_ManagerFee_inherits_Fee]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[FeeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'FeeSet_Rebate'
ALTER TABLE [dbo].[FeeSet_Rebate]
ADD CONSTRAINT [FK_Rebate_inherits_Fee]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[FeeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------